package com.action.boot.jpa.controller;

import com.action.boot.jpa.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Wuxiang on 2017/3/27.
 */
@EnableCaching
@RestController
public class CacheController {
    @Autowired
    CacheService cacheService;

    @RequestMapping(value = "/cache",method = RequestMethod.GET)
    public String home() {
//        System.out.println("调用第1次：" + cacheService.getData("data1"));
//        System.out.println("调用第2次：" + cacheService.getData("data2"));
//        System.out.println("调用第3次：" + cacheService.getData("data1"));  //从缓存获取，不调用service
//        System.out.println("调用第4次：" + cacheService.getData("data2"));  //从缓存获取，不调用service
//        System.out.println("调用第5次：" + cacheService.getData("data"));
//        System.out.println("总共调用" + CacheService.getCount() + "次");

        System.out.println(cacheService.getData("a"));
        System.out.println(cacheService.getData("a"));
        cacheService.deleteData("a");
        System.out.println(cacheService.getData("a"));
        System.out.println(cacheService.getData("a"));

        return "Cache Controller End!";
    }
}
